'use strict';

angular.module('snPaas_om').service('workorderStore',['$http','$q','baseUrl',function($http,$q,baseUrl){
	var getList = function(type,page){
		var deferred = $q.defer();
		$http.get(baseUrl.ajax+'/rest/workOrder/list',{params:{type:type,page:page}}).success(function(data, status, headers, config){
			deferred.resolve(data.data);
		});
		return deferred.promise;
	};
	var getDetail = function(id){
		var deferred = $q.defer();
		$http.get(baseUrl.ajax+'/rest/workOrder/detail',{params:{workOrderId:id}}).success(function(data, status, headers, config){
			deferred.resolve(data.data);
		});
		return deferred.promise;
	};
	var response = function(params){
		var deferred = $q.defer();
		$http({
		    method: 'POST',
		    url: baseUrl.ajax+'/rest/workOrder/reply',
		    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
		    data: $.param(params),
		}).success(function (resp) {
			deferred.resolve(resp);
		}).error(function(resp){
			deferred.reject(resp);
		});
		return deferred.promise;
	};
	var close = function(id){
		var deferred = $q.defer();
		$http.get(baseUrl.ajax+'/rest/workOrder/close',{params:{workOrderId:id}}).success(function(data, status, headers, config){
			deferred.resolve(data);
		});
		return deferred.promise;
	};
	return {
		'getList':getList,
		'getDetail':getDetail,
		'response':response,
		'close':close
	};
}]);